//
//  CustomAnnotationView.m
//  laziz_Consumer
//
//  Created by XMac on 16/11/8.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "CustomAnnotationView.h"
#import "Masonry.h"
#import "BlocksKit+UIKit.h"


@interface CustomAnnotationView ()

@property(nonatomic , strong) UILabel *titileLabel;

@property(nonatomic , strong) UILabel *detailLabel;

@end

@implementation CustomAnnotationView



- (instancetype)initWithTitle:(NSString *)xTitle detail:(NSString *)xDetail
{
    self = [super init];
    if (self) {
        [self configUIWithTitle:xTitle detail:xDetail];
    }
    return self;
}

-(void)configUIWithTitle:(NSString *)xTitle detail:(NSString *)xDetail{
    
    _titileLabel = [UILabel new];
    _titileLabel.font = [UIFont systemFontOfSize:15];
    _titileLabel.numberOfLines = 1;
    _titileLabel.text = xTitle;
    
    _detailLabel = [UILabel new];
    _detailLabel.numberOfLines = 0;
    _detailLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 50;
    _detailLabel.font = [UIFont systemFontOfSize:13];
    _detailLabel.text = xDetail;
    
    
    [self addSubview:_titileLabel];
    [self addSubview:_detailLabel];
    
    [_titileLabel makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(10);
        make.trailing.equalTo(-10);
        make.top.equalTo(10);
        
    }];
    
    [_detailLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.equalTo(10);
        make.top.equalTo(_titileLabel.bottom).equalTo(8);
    }];
}

-(CGSize)sizeThatFits:(CGSize)size{
    
    CGSize titleSize = [_titileLabel intrinsicContentSize];
    CGSize detailSize = [_detailLabel intrinsicContentSize];
    
    return CGSizeMake(MIN(MAX(titleSize.width, detailSize.width)+ 10 + 10, SCREEN_WIDTH - 20), 10 + titleSize.height + 8 + detailSize.height + 10);
}

@end
